package com.winai.launcher.override;

import android.app.Activity;
import android.app.Application;
import android.os.Bundle;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.winai.launcher.common.GlobalPublisher;

/**
 * 作者：康少
 * 时间：2020/5/15
 * 说明：activity生命周期回调
 */
public class ActivityLifecycleListener implements Application.ActivityLifecycleCallbacks {
    private final String TAG = "ActivityLifecycle";

    @Override
    public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {
        String simpleName = activity.getClass().getSimpleName();
        Log.d(TAG, "进入 " + simpleName + " 的 onActivityCreated");
    }

    @Override
    public void onActivityStarted(@NonNull Activity activity) {
        String simpleName = activity.getClass().getSimpleName();
        Log.d(TAG, "进入 " + simpleName + " 的 onActivityStarted");
    }

    @Override
    public void onActivityResumed(@NonNull Activity activity) {
        String simpleName = activity.getClass().getSimpleName();
        Log.d(TAG, "进入 " + simpleName + " 的 onActivityResumed");
    }

    @Override
    public void onActivityPaused(@NonNull Activity activity) {
        String simpleName = activity.getClass().getSimpleName();
        Log.d(TAG, "进入 " + simpleName + " 的 onActivityPaused");
    }

    @Override
    public void onActivityStopped(@NonNull Activity activity) {
        String simpleName = activity.getClass().getSimpleName();
        Log.d(TAG, "进入 " + simpleName + " 的 onActivityStopped");
    }

    @Override
    public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) {

    }

    @Override
    public void onActivityDestroyed(@NonNull Activity activity) {
        String simpleName = activity.getClass().getSimpleName();
        Log.d(TAG, "进入 " + simpleName + " 的 onActivityDestroyed");
        GlobalPublisher.removeListener(activity);
    }
}
